﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyTest {

    /// <summary>
    /// Javascript element.
    /// </summary>
    public class JavaScript : IElement {

        /// <summary>
        /// String containing a javascript command to be executed.
        /// </summary>
        public string JavaScriptCommand { get; set; }

        /// <summary>
        /// Create a new JavaScript object.
        /// </summary>
        /// <param name="javascript">Text of the javascript command to be excecuted.</param>
        public JavaScript(string javascript) {
            JavaScriptCommand = javascript;
            Focus = new Focus();
        }

        /// <summary>
        /// Create a new JavaScript object on the Focus container passed.
        /// </summary>
        /// <param name="javascript">Text of the javascript command to be excecuted.</param>
        /// <param name="focus">Document container with controls to search for.</param>
        public JavaScript(string javaScript, Focus focus)
            : this(javaScript) {
            Focus = focus;
        }

        /// <summary>
        /// Execute the javascript command contained in this object.
        /// </summary>
        public override void Click() {
            if (Focus != null)
                Focus.Go();
            Action.ExecuteJavaScript(JavaScriptCommand);
        }

    }
}
